package bintree;

	public class methods {
		
		Node root = null;
		int depth = 0;
		
		Node addNode(int value) {
			Node node = root;
			if(root == null) {
				root = new Node(value, null);
				return root;
			}
			
			while(node != null)
				if(value <= node.value) {
					if(node.left == null) {
						node.left = new Node(value, node);
						return node.left;
					}
					else
						node = node.left;
				}
				else {
					if(node.right == null) {
						node.right = new Node(value, node);
						return node.right;
					}
					else
						node = node.right;
				}
			
			return null;
		}
		
		void printTree() {
			printTree(root, 0);
		}
		
		private void printTree(Node node, int level) {
			if(node.right != null)
				 printTree(node.right, level+1);
			 
			for(int k = 0; k < level; k++)
				System.out.print("\t");
			System.out.println(node.value);
			 
			if(node.left != null)
				printTree(node.left, level+1);
		}
		
		class Node {
			int value;
			Node left;
			Node right;
			Node me;
			Node parent;
			
			Node(int value, Node parent) {
				this.value = value;
				this.parent = parent;
			}
		}
	}
